import sdk from '../core/index';
import { ClientManage } from '../core/index';
import base_component from "../component/base_component";
import pos_component from "../component/pos_component";
import enemy from "../core/rpg/entity/enemy";
import { wordMap } from "../core/rpg/wordMap";
import { ClientAction } from "../shared/api_bot/IMassage";
import { analysisIntent, baseScene } from "../core/tool/baseScene";
import { ComType } from "../core/tool/component";
import { mathType } from "../core/tool/face";
import { TaskService } from "../service/TaskService";
import { PositionService } from '../service/PositionService';

export class scene extends baseScene {
    constructor() {
        super();
        this.map.name = '十日终焉';
        this.map.enemyCfg = '十日终焉';
        this.registerIntent(mathType.模糊匹配, '复读', true, this.test);
    }
    
    async tick(data: analysisIntent): Promise<void> {
        let com_pos = data.player.getComponent(ComType.位置) as pos_component;
        let cell = this.map.checkPos(data.player);
    }

    test(data: analysisIntent) {
        console.log('测试');
        let msg = { action: ClientAction.text, Message: data.Message, info: { text: data.Message.content } };
        ClientManage.sendMsg(data.ClientInfo, msg);
    }
       // 位置（重写父类方法）
    onPosition(data: analysisIntent) {
        const result = PositionService.getPositionInfo(this.map, data.player);
        if (!result.success) {
            data.player.client_text(result.message);
            return;
        }
        
        // 获取位置信息卡片
        const card = result.card!;
        
        // 注册按钮意图
        this.registerButtonIntents(card, [
            { text: '移动', action: 'handleMove', mathType: mathType.完全匹配 },
            { text: '探索', action: 'handleExplore', mathType: mathType.完全匹配 },
            { text: '战斗', action: 'handleBattle', mathType: mathType.完全匹配 },
            { text: '回城', action: 'onBackHome', mathType: mathType.完全匹配 },
            // { text: '侦察', action: 'handleSpy', mathType: mathType.开头匹配 },
            // { text: '捕捉', action: 'handleCapture', mathType: mathType.开头匹配 },
            { text: '任务', action: 'taskbar', mathType: mathType.完全匹配 }
        ]);
        
        data.player.client_text(card.getText());
    }
  
    // 战斗 - 使用新的 SDK 方式
    handleBattle(data: analysisIntent) {
        const battle = this.map.createBattleAll(data.player);
        if(!battle){
            return;
        }
        // 设置击杀回调
        battle.onKill((killLog: any, battleCore: any) => {
            // 处理击杀奖励
            const reward = sdk.prop.PolicyReward_击杀('野外击杀怪物', killLog, this.map.name);
            if (reward && reward.length > 0) {
                // 使用 battleCore.addReward 添加到 rewardMap，而不是直接加到背包
                battleCore.addReward(killLog.unit, reward);
            }
        });
        
        // 开始战斗
        battle.start((battleData: any) => {
            const clientCom = battleData.body.getComponent(ComType.client) as any;
            clientCom.client_text(battleData.card.getText());
        });
    }
}
export default new scene();